//
//  HelperUtil.m
//  SQLite（购物）
//
//  Created by Yock Deng on 15/8/22.
//  Copyright (c) 2015年 蓝桥. All rights reserved.
//

#import "HelperUtil.h"



//#import <sys/utsname.h>
#include <mach/mach.h>
//#import <sys/sysctl.h>
//#import <sys/stat.h>
#import "NSDictionary+log.h"

//获取内存
#import <sys/types.h>
#import <sys/sysctl.h>
#import <mach/host_info.h>
#import <mach/mach_host.h>
#import <mach/task_info.h>
#import <mach/task.h>
#import <mach-o/ldsyms.h>
#import <mach-o/ldsyms.h>
#include <limits.h>
#include <mach-o/dyld.h>
#include <mach-o/nlist.h>
#include <string.h>
#import <mach-o/loader.h>
#import "JSONKit.h"






@implementation HelperUtil

static NSMutableArray *_UUIDRecordArray;

/**
 图片裁剪，适用于圆形头像之类
 
 @param image 要切圆的图片
 @param borderWidth 边框的宽度
 @param color 边框的颜色
 @return 切圆的图片
 */
+ (UIImage *)imageWithClipImage:(UIImage *)image borderWidth:(CGFloat)borderWidth borderColor:(UIColor *)color;
{
    // 图片的宽度和高度
    CGFloat imageWH = image.size.width;
    
    // 设置圆环的宽度
    CGFloat border = borderWidth;
    
    // 圆形的宽度和高度
    CGFloat ovalWH = imageWH + 2 * border;
    
    // 1.开启上下文
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(ovalWH, ovalWH), NO, 0);
    
    // 2.画大圆
    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, ovalWH, ovalWH)];
    
    [color set];
    
    [path fill];
    
    // 3.设置裁剪区域
    UIBezierPath *clipPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(border, border, imageWH, imageWH)];
    [clipPath addClip];
    
    // 4.绘制图片
    [image drawAtPoint:CGPointMake(border, border)];
    
    // 5.获取图片
    UIImage *clipImage = UIGraphicsGetImageFromCurrentImageContext();
    
    // 6.关闭上下文
    UIGraphicsEndImageContext();
    return clipImage;
}

+ (UIColor *) colorWithHexString: (NSString *) stringToConvert
{
    NSString *cString = [[stringToConvert stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    
    // String should be 6 or 8 characters
    if ([cString length] < 6) return [UIColor colorWithWhite:1.0 alpha:0.5];
    
    // strip 0X if it appears
    if ([cString hasPrefix:@"0X"]) cString = [cString substringFromIndex:2];
    if ([cString hasPrefix:@"#"]) cString = [cString substringFromIndex:1];
    if ([cString length] != 6) return [UIColor colorWithWhite:1.0 alpha:0.5];
    // Separate into r, g, b substrings
    NSRange range;
    range.location = 0;
    range.length = 2;
    NSString *rString = [cString substringWithRange:range];
    
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    
    // Scan values
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    
    return [UIColor colorWithRed:((float) r / 255.0f)
                           green:((float) g / 255.0f)
                            blue:((float) b / 255.0f)
                           alpha:1.0f];
}

+(UIViewController *)jsd_getCurrentViewController;
{
    
    UIViewController* currentViewController = [self jsd_getRootViewController];
    BOOL runLoopFind = YES;
    while (runLoopFind) {
        if (currentViewController.presentedViewController) {
            
            currentViewController = currentViewController.presentedViewController;
        } else if ([currentViewController isKindOfClass:[UINavigationController class]]) {
            
            UINavigationController* navigationController = (UINavigationController* )currentViewController;
            currentViewController = [navigationController.childViewControllers lastObject];
        } else if ([currentViewController isKindOfClass:[UITabBarController class]]) {
            
            UITabBarController* tabBarController = (UITabBarController* )currentViewController;
            currentViewController = tabBarController.selectedViewController;
        } else {
            
            NSUInteger childViewControllerCount = currentViewController.childViewControllers.count;
            if (childViewControllerCount > 0) {
                
                currentViewController = currentViewController.childViewControllers.lastObject;
                
                return currentViewController;
            } else {
                
                return currentViewController;
            }
        }
        
    }
    return currentViewController;
}

+ (UIViewController *)jsd_getRootViewController;
{
    
    UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
    //    NSAssert(window, @"The window is empty");
    return window.rootViewController;
}


//手机剩余存储空间
+ (NSString *)freeDiskSpaceInBytes;
{
    NSString *version = [UIDevice currentDevice].systemVersion;
    NSString *str = @"";
    if (version.doubleValue >= 11.0) {
        // 针对 11.0 以上的iOS系统进行处理
        NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:NSTemporaryDirectory()];
        NSDictionary *results = [fileURL resourceValuesForKeys:@[NSURLVolumeAvailableCapacityForImportantUsageKey] error:nil];
        str = results[NSURLVolumeAvailableCapacityForImportantUsageKey];
        NSLog(@"剩余可用空间:%@",results[NSURLVolumeAvailableCapacityForImportantUsageKey]);
        // 这里拿到的值的单位是bytes，iOS11是这样算的1000MB = 1，1000进制算的
        // bytes->KB->MB->G
    } else {
        // 针对 11.0 以下的iOS系统进行处理
        struct statfs  buf;
        unsigned long long freeSpace = -1;
        if (statfs("/var", &buf) >= 0) {
            freeSpace = (unsigned long long)(buf.f_bsize * buf.f_bavail);
        }
       str = [NSString stringWithFormat:@"%0.2lld",freeSpace];//手机剩余存储空间为：mb 尚未测试
    }
    
    return str;
}

//磁盘总空间
+ (NSString *)getTotalDiskSpace;
{
    NSError *error = nil;
    NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:&error];
    if (error) return @"-1";
    int64_t space =  [[attrs objectForKey:NSFileSystemSize] longLongValue];
    if (space < 0) space = -1;
    NSString *diskSpace = [NSString stringWithFormat:@"%.2lld", space]; //byte

    return diskSpace;
}

+(void) logMemoryInfo;
{
    
    
    int mib[6];
    mib[0] = CTL_HW;
    mib[1] = HW_PAGESIZE;
    
    int pagesize;
    size_t length;
    length = sizeof (pagesize);
    if (sysctl (mib, 2, &pagesize, &length, NULL, 0) < 0)
    {
        fprintf (stderr, "getting page size");
    }
    
    mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
    
    vm_statistics_data_t vmstat;
    if (host_statistics (mach_host_self (), HOST_VM_INFO, (host_info_t) &vmstat, &count) != KERN_SUCCESS)
    {
        fprintf (stderr, "Failed to get VM statistics.");
    }
    task_basic_info_64_data_t info;
    unsigned size = sizeof (info);
    task_info (mach_task_self (), TASK_BASIC_INFO_64, (task_info_t) &info, &size);
    
    double unit = 1024 * 1024;
//    double unit = 1;

    double total = (vmstat.wire_count + vmstat.active_count + vmstat.inactive_count + vmstat.free_count) * pagesize / unit;
    double wired = vmstat.wire_count * pagesize / unit;
    double active = vmstat.active_count * pagesize / unit;
    double inactive = vmstat.inactive_count * pagesize / unit;
    double free = vmstat.free_count * pagesize / unit;
    double resident = info.resident_size / unit;
    NSLog(@"===================================================");
    NSLog(@"Total:%.2lfMb", total);
    NSLog(@"Wired:%.2lfMb", wired);
    NSLog(@"Active:%.2lfMb", active);
    NSLog(@"Inactive:%.2lfMb", inactive);
    NSLog(@"Free:%.2lfMb", free);
    NSLog(@"Resident:%.2lfMb", resident);
}
//内存总空间 精确
+(NSString *)getTotalMemoryInfo;
{
    double totalSize = [NSProcessInfo processInfo].physicalMemory;
    NSString *totalMemoryInfo = [NSString stringWithFormat:@"%.2lf", totalSize];
    return totalMemoryInfo;
}

//空闲内存
+(NSString *)getFreeMemoryInfo;
{
    int mib[6];
    mib[0] = CTL_HW;
    mib[1] = HW_PAGESIZE;
    
    int pagesize;
    size_t length;
    length = sizeof (pagesize);
    if (sysctl (mib, 2, &pagesize, &length, NULL, 0) < 0)
    {
        fprintf (stderr, "getting page size");
    }
    
    mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
    
    vm_statistics_data_t vmstat;
    if (host_statistics (mach_host_self (), HOST_VM_INFO, (host_info_t) &vmstat, &count) != KERN_SUCCESS)
    {
        fprintf (stderr, "Failed to get VM statistics.");
    }
    task_basic_info_64_data_t info;
    unsigned size = sizeof (info);
    task_info (mach_task_self (), TASK_BASIC_INFO_64, (task_info_t) &info, &size);
    
//    double unit = 1024 * 1024;//unit = 1 byte,unit = 1024*1024 是mb
    double unit = 1;
    double total = (vmstat.wire_count + vmstat.active_count + vmstat.inactive_count + vmstat.free_count) * pagesize / unit;
    double wired = vmstat.wire_count * pagesize / unit;
    double active = vmstat.active_count * pagesize / unit;
    double inactive = vmstat.inactive_count * pagesize / unit;
    double free = vmstat.free_count * pagesize / unit;
    double resident = info.resident_size / unit;
    NSLog(@"===================================================");
//    NSLog(@"Total:%.2lfMb", total);
    //    NSLog(@"Wired:%.2lfMb", wired);
    //    NSLog(@"Active:%.2lfMb", active);
    //    NSLog(@"Inactive:%.2lfMb", inactive);
//        NSLog(@"Free:%.2lfMb", free);
    //    NSLog(@"Resident:%.2lfMb", resident);
    
    NSString *freeMemoryInfo = [NSString stringWithFormat:@"%.2lf", free];//Mb
    NSLog(@"freeMemoryInfo :%@", freeMemoryInfo);
    
    return freeMemoryInfo;
}

+(void) print_free_memory;
{
    mach_port_t host_port;
    mach_msg_type_number_t host_size;
    vm_size_t pagesize;
    
    host_port = mach_host_self();
    host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
    host_page_size(host_port, &pagesize);
    
    vm_statistics_data_t vm_stat;
    
    if (host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size) != KERN_SUCCESS) {
        NSLog(@"Failed to fetch vm statistics");
    }
    
    /* Stats in bytes */
    natural_t mem_used = (vm_stat.active_count +
                          vm_stat.inactive_count +
                          vm_stat.wire_count) * pagesize;
    natural_t mem_free = vm_stat.free_count * pagesize;
    natural_t mem_total = mem_used + mem_free;
    NSLog(@"used: %u free: %u total: %u", mem_used, mem_free, mem_total);
}

#pragma mark - 是否被破解
+ (BOOL)isJailbreak;
{
    static BOOL isjbroken = NO;
    if (isjbroken) {
        return isjbroken;
    }
    @try {
        NSArray *paths = [NSArray arrayWithObjects:
                          @"/User/Applications/",
                          @"/Applications/Cydia.app",
                          @"/Library/MobileSubstrate/MobileSubstrate.dylib",
                          @"/bin/bash",
                          @"/usr/sbin/sshd",
                          @"/etc/apt",
                          nil];
        
        for (NSString *one in paths) {
            if ([[NSFileManager defaultManager] fileExistsAtPath:one]) {
                isjbroken = YES;
            }
        }
    } @catch (NSException *exception) {
        NSLog(@"Jailbroken exception:%@",exception);
    }
    
    return isjbroken;
}

//获取CPU类型
+(NSString *)getCPUType;
{
    host_basic_info_data_t hostInfo;
    mach_msg_type_number_t infoCount;
    
    infoCount = HOST_BASIC_INFO_COUNT;
    host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
    
    switch (hostInfo.cpu_type) {
        case CPU_TYPE_ARM:
            return @"CPU_TYPE_ARM";
            break;
            
        case CPU_TYPE_ARM64:
            return @"CPU_TYPE_ARM64";
            break;
            
        case CPU_TYPE_X86:
            return @"CPU_TYPE_X86";
            break;
            
        case CPU_TYPE_X86_64:
            return @"CPU_TYPE_X86_64";
            break;
            
        default:
            return @"";
            break;
    }
}

//个人觉得 sdk开发时候 最好不要用第三方 最好可以用最原始的方法 替换 此处仅做sdk封装使用  留存
+(void)POST:(NSString *)urlStr params:(NSDictionary *)params  sucess:(void (^)(NSURLSessionDataTask *task, id responseObject))sucess failure:(void (^)(NSURLSessionDataTask *task, NSError * error))failure;
{
    urlStr = [self URLEncodedStringValue:params url:urlStr];
    NSURL *URL = [NSURL URLWithString:urlStr];
    
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
    [request setHTTPMethod:@"POST"];
    NSString *dataStr =[params descriptionWithLocale:nil];
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
//    [request addValue:@"application/json" forHTTPHeaderField:@"Accept"];

//    if (![request valueForHTTPHeaderField:@"Content-Type"]) {
//        [request addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
//    }
    request.HTTPBody = [dataStr dataUsingEncoding:NSUTF8StringEncoding];
//    application/x-www-form-urlencoded;charset=UTF-8
//    request.h
    
//    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
//    configuration set
    
    NSURLSession *session = [NSURLSession sharedSession];
    __block NSURLSessionDataTask *task= nil;
    task = [session dataTaskWithRequest:request
                      completionHandler:
            ^(NSData *data, NSURLResponse *response, NSError *error) {
                
                if (error) {
                    failure(task,error);
                } else {
                    NSError *jsonError = nil;
                    id notesJSON =
                    [NSJSONSerialization JSONObjectWithData:data
                                                    options:NSJSONReadingAllowFragments
                                                      error:&jsonError];
                    if (!jsonError) {
                        if (sucess) {
                            sucess(task,notesJSON);
                        }
                    } else {
                        if (failure) {
                            failure(task,jsonError);
                        }
                        
                    }
                }
            }];
    
    [task resume];
}

+ (NSString *)URLEncodedStringValue:(NSDictionary *)Parameter url:(NSString *)urlStr;
{
    if (Parameter) {
        urlStr = [urlStr stringByAppendingString:@"?"];
        NSArray *keys =[Parameter allKeys];
        for (int i=0;i<keys.count;i++) {
            NSString *key = [keys objectAtIndex:i];
            NSString *value = [Parameter objectForKey:key];
            if (i==0) {
                urlStr = [urlStr stringByAppendingFormat:@"%@=%@",key,value];
            } else {
                urlStr = [urlStr stringByAppendingFormat:@"&%@=%@",key,value];
            }
        }
    }
    urlStr = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLQueryAllowedCharacterSet];
    
    return urlStr;
}

//字符串转字典
+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString;
{
    if (jsonString == nil) {
        return nil;
    }
//    jsonString = [jsonString stringByReplacingOccurrencesOfString:@"\\n" withString:@""];
//    jsonString = [jsonString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
//    jsonString = [jsonString stringByReplacingOccurrencesOfString:@"\\" withString:@""];//-
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
    if(err) {
        NSLog(@"json解析失败：%@",err);
        
       NSDictionary *dic =[jsonData objectFromJSONDataWithParseOptions:JKParseOptionLooseUnicode error:&err];
//        return  dic;
        return nil;
    }
    return dic;
}


+ (NSString *)getTotalMemorySize;

{
    
    
//    vm_statistics_data_t vmStats;
//    mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
//    kern_return_t kernReturn = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmStats, &infoCount);
//
//    if (kernReturn != KERN_SUCCESS)
//    {
////        return NSNotFound;
//    }
//    double mem = (vm_page_size * vmStats.free_count) + (vmStats.inactive_count * vm_page_size);
    
//    return mem/1024.0/1024.0;
    
    double totalSize = [NSProcessInfo processInfo].physicalMemory;
    NSString *processName = [[NSProcessInfo processInfo] processName];

    NSString *freeMemoryInfo = [NSString stringWithFormat:@"%.2lf", totalSize];//Mb
    NSLog(@"totalSize:%@", freeMemoryInfo);

    return freeMemoryInfo;
    
}


+(NSString *) executableUUID
{
    const uint8_t *command = (const uint8_t *)(&_mh_execute_header + 1);
    for (uint32_t idx = 0; idx < _mh_execute_header.ncmds; ++idx) {
        if (((const struct load_command *)command)->cmd == LC_UUID) {
            command += sizeof(struct load_command);
            return [NSString stringWithFormat:@"%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
                    command[0], command[1], command[2], command[3],
                    command[4], command[5],
                    command[6], command[7],
                    command[8], command[9],
                    command[10], command[11], command[12], command[13], command[14], command[15]];
        } else {
            command += ((const struct load_command *)command)->cmdsize;
        }
    }
    return nil;
}

 NSUUID *ExecutableUUID(void)
{
    const struct mach_header *executableHeader = NULL;
    for (uint32_t i = 0; i < _dyld_image_count(); i++)
    {
        const struct mach_header *header = _dyld_get_image_header(i);
        if (header->filetype == MH_EXECUTE)
        {
            executableHeader = header;
            break;
        }
    }
    
    if (!executableHeader)
        return nil;
    
    BOOL is64bit = executableHeader->magic == MH_MAGIC_64 || executableHeader->magic == MH_CIGAM_64;
    uintptr_t cursor = (uintptr_t)executableHeader + (is64bit ? sizeof(struct mach_header_64) : sizeof(struct mach_header));
    const struct segment_command *segmentCommand = NULL;
    for (uint32_t i = 0; i < executableHeader->ncmds; i++, cursor += segmentCommand->cmdsize)
    {
        segmentCommand = (struct segment_command *)cursor;
        if (segmentCommand->cmd == LC_UUID)
        {
            const struct uuid_command *uuidCommand = (const struct uuid_command *)segmentCommand;
            return [[NSUUID alloc] initWithUUIDBytes:uuidCommand->uuid];
        }
    }
    
    return nil;
}

+ (NSUUID *)ExecutableUUID
{
    const struct mach_header *executableHeader = NULL;
    for (uint32_t i = 0; i < _dyld_image_count(); i++)
    {
        const struct mach_header *header = _dyld_get_image_header(i);
        if (header->filetype == MH_EXECUTE)
        {
            executableHeader = header;
            break;
        }
    }
    
    if (!executableHeader)
        return nil;
    
    BOOL is64bit = executableHeader->magic == MH_MAGIC_64 || executableHeader->magic == MH_CIGAM_64;
    uintptr_t cursor = (uintptr_t)executableHeader + (is64bit ? sizeof(struct mach_header_64) : sizeof(struct mach_header));
    const struct segment_command *segmentCommand = NULL;
    for (uint32_t i = 0; i < executableHeader->ncmds; i++, cursor += segmentCommand->cmdsize)
    {
        segmentCommand = (struct segment_command *)cursor;
        if (segmentCommand->cmd == LC_UUID)
        {
            const struct uuid_command *uuidCommand = (const struct uuid_command *)segmentCommand;
            return [[NSUUID alloc] initWithUUIDBytes:uuidCommand->uuid];
        }
    }
    
    return nil;
}

+ (NSDictionary *)getUUIDDictionary {
        NSDictionary *uuidDic = [[NSDictionary alloc] init];
        
        int imageCount = (int)_dyld_image_count();
        
        for(int iImg = 0; iImg < imageCount; iImg++) {
                
                JYGetBinaryImage(iImg);
            }
         
        return uuidDic;
}
// 获取 Load Command, 会根据 header 的 magic 来判断是 64 位 还是 32 位
static uintptr_t firstCmdAfterHeader(const struct mach_header* const header) {
        switch(header->magic) {
                    case MH_MAGIC:
                    case MH_CIGAM:
                        return (uintptr_t)(header + 1);
                    case MH_MAGIC_64:
                    case MH_CIGAM_64:
                        return (uintptr_t)(((struct mach_header_64*)header) + 1);
                    default:
                        return 0;
            }
}
bool JYGetBinaryImage(int index) {
        const struct mach_header* header = _dyld_get_image_header((unsigned)index);
        if(header == NULL) {
                return false;
            }
         
        uintptr_t cmdPtr = firstCmdAfterHeader(header);
        if(cmdPtr == 0) {
                return false;
            }
         
        uint8_t* uuid = NULL;
         
        for(uint32_t iCmd = 0; iCmd < header->ncmds; iCmd++)
            {
                    struct load_command* loadCmd = (struct load_command*)cmdPtr;
                     
                    if (loadCmd->cmd == LC_UUID) {
                            struct uuid_command* uuidCmd = (struct uuid_command*)cmdPtr;
                            uuid = uuidCmd->uuid;
                            break;
                        }
                    cmdPtr += loadCmd->cmdsize;
                }
        const char* path = _dyld_get_image_name((unsigned)index);
        NSString *imagePath = [NSString stringWithUTF8String:path];
        NSArray *array = [imagePath componentsSeparatedByString:@"/"];
        NSString *imageName = array[array.count - 1];
        
        NSLog(@"buffer->name:%@",imageName);
        
        const char* result = nil;
        if(uuid != NULL)
            {
                    result = uuidBytesToString(uuid);
                    NSString *lduuid = [NSString stringWithUTF8String:result];
                    NSLog(@"buffer->uuid:%@",lduuid);
                }
         
        return true;
}
static const char* uuidBytesToString(const uint8_t* uuidBytes) {
        CFUUIDRef uuidRef = CFUUIDCreateFromUUIDBytes(NULL, *((CFUUIDBytes*)uuidBytes));
        NSString* str = (__bridge_transfer NSString*)CFUUIDCreateString(NULL, uuidRef);
        CFRelease(uuidRef);
         
        return cString(str);
}
const char* cString(NSString* str) {
        return str == NULL ? NULL : strdup(str.UTF8String);
}


#pragma mark 字典转化字符串
+(NSString*)dictionaryToJson:(NSDictionary *)dic
{
    NSError *parseError = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];
    
    return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}

+ (NSString *)dataTOjsonString:(id)object;
{
    
    NSString *jsonString = nil;
    NSError *error;

    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:object
                                                       options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
                                                         error:&error];
    if ( !jsonData ) {
        NSLog(@"Got an error: %@", error);
    } else {
        jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    }
    return jsonString;
}


@end
